﻿using System;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;

namespace Linker.TaskCenter.Migrations
{
    public partial class AddTaskEntity : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                "service",
                table => new
                {
                    Id = table.Column<long>("bigint", nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    SystemId = table.Column<Guid>("char(36)", nullable: false),
                    SystemName = table.Column<string>("varchar(128) CHARACTER SET utf8mb4", maxLength: 128,
                        nullable: false),
                    Method =
                        table.Column<string>("varchar(128) CHARACTER SET utf8mb4", maxLength: 128, nullable: false),
                    Url = table.Column<string>("varchar(128) CHARACTER SET utf8mb4", maxLength: 128, nullable: false),
                    Parameter = table.Column<string>("longtext CHARACTER SET utf8mb4", nullable: true),
                    Response = table.Column<string>("longtext CHARACTER SET utf8mb4", nullable: true),
                    Description = table.Column<string>("varchar(255) CHARACTER SET utf8mb4", maxLength: 255,
                        nullable: true),
                    CreationTime = table.Column<DateTime>("datetime(6)", nullable: false),
                    CreatorId = table.Column<Guid>("char(36)", nullable: true),
                    LastModificationTime = table.Column<DateTime>("datetime(6)", nullable: true),
                    LastModifierId = table.Column<Guid>("char(36)", nullable: true),
                    IsDeleted = table.Column<bool>("tinyint(1)", nullable: false, defaultValue: false),
                    DeleterId = table.Column<Guid>("char(36)", nullable: true),
                    DeletionTime = table.Column<DateTime>("datetime(6)", nullable: true)
                },
                constraints: table => { table.PrimaryKey("PK_service", x => x.Id); });

            migrationBuilder.CreateTable(
                "task",
                table => new
                {
                    Id = table.Column<long>("bigint", nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    ServiceId = table.Column<long>("bigint", nullable: false),
                    Request = table.Column<string>("longtext CHARACTER SET utf8mb4", nullable: true),
                    Response = table.Column<string>("longtext CHARACTER SET utf8mb4", nullable: true),
                    ResponseResult = table.Column<int>("int", nullable: false),
                    Error = table.Column<string>("longtext CHARACTER SET utf8mb4", nullable: true),
                    Status = table.Column<int>("int", nullable: false),
                    TaskUId = table.Column<Guid>("char(36)", nullable: false),
                    Name = table.Column<string>("varchar(128) CHARACTER SET utf8mb4", maxLength: 128, nullable: true),
                    Remark = table.Column<string>("varchar(128) CHARACTER SET utf8mb4", maxLength: 128, nullable: true),
                    CreationTime = table.Column<DateTime>("datetime(6)", nullable: false),
                    CreatorId = table.Column<Guid>("char(36)", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_task", x => x.Id);
                    table.ForeignKey(
                        "FK_task_service_ServiceId",
                        x => x.ServiceId,
                        "service",
                        "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                "IX_task_ServiceId",
                "task",
                "ServiceId");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                "task");

            migrationBuilder.DropTable(
                "service");
        }
    }
}